import { Component } from "@/components/low-code/core";
import { LowCodeImp } from "@/components/low-code/core/type";
import { Cell } from "@/components/low-code/core/cell";
import { Tab } from "@/components/low-code/core/tab";
import { message } from 'ant-design-vue';

export const useComponentPretreatment = (lowCode: LowCodeImp, component: { component?: string, items: Array<any> }, index: number) => {
    console.log('component.component',component.component)
    /****
     * 如果是弹框组件 阻止拖入其他容器组件 只能在当前根节点拖入
     */
    if (component.component!='Root' && component.items[index].component == "Modal") {
        component.items.splice(index, 1);
        message.warning("弹框组件只能拖入最外层容器");
        return true;
    }


        /****
     * 如果父级是 form 容器组件 需要禁止 form容器组件拖入
     */
        if (component.component == "Form" && component.items[index].component == "Form") {
            component.items.splice(index, 1);
            message.warning("Form容器组件禁止嵌套");
            return true;
        }
    

    /****
     * 如果是弹框 需要暂时禁止其他组件拖入
     */
    if (!component.component && component.items[index].component == "Modal") {
        lowCode.disabled = true;
    }


    /****
     * 格栅组件需要对默认cell实例化
     */
    if (component.items[index].component == "Row") {
        component.items[index].items = component.items[
            index
        ].items?.map((cell: any) => {
            return new Cell(cell, lowCode);
        });
    }

        /****
     * tabs组件需要对默认Tab实例化
     */
        if (component.items[index].component == "Tabs") {
            component.items[index].items = component.items[
                index
            ].items?.map((tab: any) => {
                return new Tab(tab, lowCode);
            });
        }

}